<?php
/**
 * Created by PhpStorm.
 * User: gyccvvh
 * Date: 2018-06-14
 * Time: 15:33
 */

namespace app\merchant\controller;


use thans\Ret;
use think\Controller;
use think\Loader;
use think\Log;
use think\Request;

class App extends Controller
{
    protected $request = null;
    protected $ret = null;
    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->request = $request;
    }
    public function _initialize()
    {
        parent::_initialize();
        $this->ret = Ret::i();
        $this->now_uri = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
        $this->now_uri = strtolower($this->now_uri);
        $this->assign('base_uri', url($this->now_uri));
    }

    public function assign($name, $value = '')
    {
        if($this->request->isAjax() && !$this->request->get("no_json")) {
            $this->ret->setData($name, $value);
        }else {
            parent::assign($name, $value);
        }
    }

    public function fetch($template = '', $vars = [], $replace = [], $config = [])
    {
        if($this->request->isAjax() && !$this->request->get("no_json")) {
            return $this->ret->toJson();
        }else {
            return parent::fetch($template, $vars, $replace, $config);
        }
    }

}